<?php

namespace app\common\model;

use think\Model;

class Wdcate extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性
    protected $append = [
        'user_level_text'
    ];

    protected static function init()
    {
        self::afterInsert(function ($row) {
            if (!$row['weigh']) {
                $row->save(['weigh' => $row['id']]);
            }
        });
    }

    /**
     * 获取用户组名称列表
     */
    public function getUserLevelTextAttr($value, $data)
    {
        $groupNames = $data['user_level_id']>0?UserLevel::where('id',  $data['user_level_id'])->value('name'):'不需要';
        return $groupNames;
    }
}